﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EPE.DALFactory;
using EPE.IDAL;
using System.Data;
using EPE.Model;

namespace EPE.BLL
{
    public class Authentication
    {
        private readonly IAuthentication dal = DataAccessFactory.CreateAuthentication();

        public bool LoginCheckPassWord(string argLoginName, string argPassword)
        {
            DataSet ds = dal.LoginCheckPassWord(argLoginName, argPassword);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public CLoginUser GetUserInfo(string argLoginName)
        {
            DataSet retDs = new DataSet();
            DataSet retMenu = new DataSet();

            CLoginUser rtnCLoginUser = new CLoginUser();

            try
            {
                retDs = dal.GetUserInfo(argLoginName);

                #region"base info"
                if (retDs.Tables[0].Rows.Count > 0)
                {
                    rtnCLoginUser.UserId = Convert.ToInt32(retDs.Tables[0].Rows[0]["UserId"]);
                    rtnCLoginUser.LoginName = retDs.Tables[0].Rows[0]["account"].ToString();
                    rtnCLoginUser.UserName = retDs.Tables[0].Rows[0]["UserName"].ToString();
                    rtnCLoginUser.CompanyId = Convert.ToInt32(retDs.Tables[0].Rows[0]["CompanyId"].ToString());
                    rtnCLoginUser.CompanyName = retDs.Tables[0].Rows[0]["CompanyName"].ToString();
                    rtnCLoginUser.DepartmentId = Convert.ToInt32(retDs.Tables[0].Rows[0]["DepartMentId"].ToString());
                    rtnCLoginUser.DepartmentName = retDs.Tables[0].Rows[0]["DepartmentName"].ToString();             
                    rtnCLoginUser.PostId = Convert.ToInt32(retDs.Tables[0].Rows[0]["PostId"].ToString());
                    rtnCLoginUser.PostName = retDs.Tables[0].Rows[0]["PostName"].ToString();
                    rtnCLoginUser.AreaId = Convert.ToInt32(retDs.Tables[0].Rows[0]["AreaId"].ToString());
                }
                #endregion

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return rtnCLoginUser;
        }

    }
}
